package com.galudisu.handsonic.modules.system.domain;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.galudisu.handsonic.base.AudiTableEntity;

import javax.persistence.*;
import java.util.HashSet;
import java.util.Set;

/**
 * @author Barudisshu
 */
@Entity
@Table(name = "t_sys_organization")
public class Organization extends AudiTableEntity {

    private static final long serialVersionUID = 3262593872433672185L;

    @Basic
    @Column(name = "name", nullable = true, unique = true, length = 100)
    private String name;
    @Basic
    @Column(name = "identity", nullable = true, unique = true, length = 45)
    private String identity;
    @Basic
    @Column(name = "type", nullable = true)
    private Integer type;
    @Basic
    @Column(name = "leaf", nullable = true)
    private Integer leaf;
    @Basic
    @Column(name = "description", nullable = true, length = 200)
    private String description;
    @Basic
    @Column(name = "available", nullable = true)
    private Boolean available;

    //------------------------------------------------------------


    @JsonIgnore
    @ManyToOne(cascade = {CascadeType.ALL})
    @JoinColumn(name = "parent_id")
    private Organization parentId;

    @JsonIgnore
    @OneToMany(mappedBy = "parentId")
    private Set<Organization> childs = new HashSet<>();


    @JsonIgnore
    @ManyToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
    @JoinTable(name = "t_sys_user_organization",
            joinColumns = {@JoinColumn(name = "organization_id", nullable = false, updatable = false)},
            inverseJoinColumns = {@JoinColumn(name = "user_id", nullable = false, updatable = false)})
    private Set<User> users = new HashSet<>();

    public Organization(){}

    public Organization(String name,String identity){
        this.name = name;
        this.identity = identity;

    }

    // getter setter


    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getIdentity() {
        return identity;
    }

    public void setIdentity(String identity) {
        this.identity = identity;
    }

    public Integer getType() {
        return type;
    }

    public void setType(Integer type) {
        this.type = type;
    }

    public Integer getLeaf() {
        return leaf;
    }

    public void setLeaf(Integer leaf) {
        this.leaf = leaf;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public Boolean getAvailable() {
        return available;
    }

    public void setAvailable(Boolean available) {
        this.available = available;
    }

    public Organization getParentId() {
        return parentId;
    }

    public void setParentId(Organization parentId) {
        this.parentId = parentId;
    }

    public Set<Organization> getChilds() {
        return childs;
    }

    public void setChilds(Set<Organization> childs) {
        this.childs = childs;
    }

    public Set<User> getUsers() {
        return users;
    }

    public void setUsers(Set<User> users) {
        this.users = users;
    }
}
